

<?php
include "../../db_const.php";
include "../../connect.php";
include "../../connect_ado.php";
include "../../isa-lib/isa-function/isa_public_function.php";

//*****************************************************************************************************************
//	V1.0	DATCQ	Cap nhat noi dung giay phep cua ho so.
//*****************************************************************************************************************
	$v_record_id = '';
	$v_record_id = $_REQUEST['hdn_record_id'];
	//Begin//Xay dung chuoi XML chua gi tri 
	$v_list_xml_tag = "";
	if(isset($_REQUEST['hdn_list_xml_tag'])){
		$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
	}
	$v_list_xml_value = "";
	if(isset($_REQUEST['hdn_list_xml_value'])){
		$v_list_xml_value = urldecode($_REQUEST['hdn_list_xml_value']);
	}
	//echo $v_record_id.'<br>';	echo $v_list_xml_tag.'<br>';	echo $v_list_xml_value.'<br>';
	
	if(_is_sqlserver()){
		$sql = "Exec Onegate_RecordGetAllForIdList ";
		$sql = $sql ."'". $v_record_id."'" ;
		//echo $sql;exit;
		$ado_conn->SetFetchMode(ADODB_FETCH_NUM);
		$arr_record_id = $ado_conn->GetAll($sql);
		//var_dump($arr_all_record);
		//echo htmlspecialchars($arr_record_id[0][15]);
	}
	
	if($arr_record_id[0][15]!=''){
		$strXML = $arr_record_id[0][15];
	}else {
		$strXML = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
	}
	
	// Luu y cac ho so phai co noi dung giay phep...	
	for ($i=0;$i<_list_get_len($v_list_xml_tag,'!~~!');$i++){
		$xml_tag = _get_xml_tag_of_array(_list_get_at($v_list_xml_tag,$i,'!~~!'));
		$xml_value = trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,'!~~!')));

		$array_string = split("<".$xml_tag.">",$strXML);
		if(sizeof($array_string)>1){
			$array_string_2 = split("</".$xml_tag.">",$array_string[1]);
			if(sizeof($array_string_2)>1){
				$strXML = $array_string[0]."<".$xml_tag.">".$xml_value."</".$xml_tag.">".$array_string_2[1];
			}
		}
		else{
			$str = "<".$xml_tag.">";
			$str = $str .$xml_value;
			$str = $str ."</".$xml_tag.">";
			$strXML = str_replace("</data_list></root>",$str."</data_list></root>",$strXML);
		}		
		if ($xml_tag == 'registor_name') {
			$registor_name = $xml_value;
		}
	}
	//echo $registor_name;exit;
	//echo htmlspecialchars($strXML) ; exit;
	//End

	if(_is_sqlserver()){
		$license_xml_data_id = _save_XML_to_database('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_TEXT', $strXML);
		//Cap nhat noi dung 
		$sql = "Exec Onegate_LicenseUpdate " ;
		$sql = $sql . " '" .  $v_record_id."'";
		$sql = $sql . "," .  $license_xml_data_id ;
		//echo $sql; exit;
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql); 
		if (array_key_exists('RET_ERROR', $rs)) {
			$v_error = _replace_bad_char(trim($rs['RET_ERROR']));		
		}
	}
	sleep(0);
//echo ($strXML) ; exit;
	if (isset($v_error) && !is_null($v_error) && $v_error<>""){
		echo '0';
	}else{
		echo $registor_name;
	}

?>

	